package net.frankish.tools.toolbar2;

import java.awt.Color;
import java.net.URL;
import java.util.Vector;

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JPanel;

public class FrankishBar extends ContextPanel {
	private static final long serialVersionUID = 1L;
	protected Vector<String> names = new Vector();
	protected Vector<JPanel> views = new Vector();
	protected Vector<Color> colors = new Vector();

	public FrankishBar() {
	}

	public void addIcon(String context,String contextText, String tabTooltip,URL tabIcon, Color color, Action action) {
		int index;
		JPanel view;
		if ((index = names.indexOf(context)) > -1) {
			view = views.elementAt(index);
		} else {
			view = new JPanel();
			view.setBackground(Color.gray);
			view.setLayout(new ListLayout());
			names.addElement(context);
			views.addElement(view);
			colors.addElement(color);
			index = names.indexOf(context);
			addTab(context, contextText,tabTooltip,tabIcon, color, new ScrollingPanel(view));
		}
		RolloverButton button = new RolloverButton((String) action.getValue(Action.NAME), (Icon) action.getValue("LargeIcon"), (String)action.getValue("ToolTip"));
		button.addActionListener(action);
		float[] hsb = Color.RGBtoHSB(colors.get(index).getRed(),colors.get(index).getGreen(), colors.get(index).getBlue(), null);
		Color back = Color.getHSBColor(hsb[0], 0.3f, hsb[2]);
		button.setBackground(back);
		view.add(button);
		doLayout();
	}
}
